/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simulation;

import jade.content.OntoAID;
import jade.core.AID;
import jade.core.Agent;
import jade.domain.DFService;
import jade.domain.FIPAException;
import logging.LogSetup;
import org.apache.log4j.Logger;

/**
 *
 * @author Danielondon
 */
public abstract class SimulationAgent extends Agent{
    protected Logger logger = LogSetup.getLogger();
    protected int TOTAL_SLOTS;    
    protected boolean isSimulationStarted;
    protected AID marketAgent;
    protected AID controllerAgent;
    protected int SLOT_SIZE;
    
    @Override
    public void setup(){
        this.isSimulationStarted = false;        
        this.setParameters(getArguments());
    }
    
    // Agent clean-up operations here
    @Override
    protected void takeDown() {
        // Deregister from the yellow pages
        try {
            DFService.deregister(this);
        }
        catch (FIPAException fe) {
            logger.error("Closing Simulation Agent", fe);
        }
    }
    
    protected void setParameters(Object[] arguments) {
        // TODO: Set Proper values from arguments 
        if (arguments[0].getClass().equals( OntoAID.class ) ) {
            this.controllerAgent = ((OntoAID)arguments[0]);
            this.marketAgent = ((OntoAID)arguments[1]);
            //System.out.println("AID agents set propertly " + this.controllerAgent + " " + this.marketAgent);
        }        
        //logger.info(arguments[2]);
        String [] tokens = ((String)arguments[2]).split(CommonResources.STRING_SEPARATOR);
        this.TOTAL_SLOTS = Integer.valueOf(tokens[0]);
        this.SLOT_SIZE = Integer.valueOf(tokens[1]);
        
        setCustomParameters(arguments);
    }
    
    protected abstract void setCustomParameters(Object[] arguments);
}
